#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <boost/algorithm/string.hpp>
#include <jsoncpp/json/json.h>

class JSON
{
public:
    // 实现字符串的序列化
    static bool Serialize(const Json::Value &val, std::string &body)
    {
        std::stringstream ss;

        // 先实例化一个工厂类对象
        static Json::StreamWriterBuilder swb;
        // 再使用工厂类对象来生产派生类
        std::unique_ptr<Json::StreamWriter> sw(swb.newStreamWriter());
        int ret = sw->write(val, &ss);
        if (ret != 0)
        {
            std::cerr << "Json Serialize failed!" << std::endl;
            return false;
        }

        body = ss.str();
        return true;
    }

    // 实现json字符串的反序列化
    static bool UnSerialize(const std::string &body, Json::Value &val)
    {
        // 实例化工厂类对象
        static Json::CharReaderBuilder crb;
        std::unique_ptr<Json::CharReader> cr(crb.newCharReader());

        std::string errs;
        bool ret = cr->parse(body.c_str(), body.c_str() + body.size(), &val, &errs);
        if (ret == false)
        {
            std::cerr << "Json UnSerialize failed! " << errs << std::endl;
            return false;
        }

        return true;
    }
};

int main()
{
    std::vector<std::string> result;
    std::string target = "aaa\3\3\3\3\3\3bbb\3ccc";
    boost::split(result, target, boost::is_any_of("\3"), boost::token_compress_on);

    for (auto &s : result)
    {
        std::cout << s << std::endl;
    }
    return 0;
}